package com.ruoyi.jjm.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.jjm.domain.TownStatistics;
import com.ruoyi.jjm.mapper.ClientUserOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.jjm.mapper.ClientUserMapper;
import com.ruoyi.jjm.domain.ClientUser;
import com.ruoyi.jjm.service.IClientUserService;
import com.ruoyi.common.core.text.Convert;

/**
 * 村民信息Service业务层处理
 * 
 * @author tsr
 * @date 2020-07-15
 */
@Service
public class ClientUserServiceImpl implements IClientUserService 
{
    @Autowired
    private ClientUserMapper clientUserMapper;

    @Autowired
    private ClientUserOrderMapper clientUserOrderMapper;

    /**
     * 查询村民信息
     * 
     * @param id 村民信息ID
     * @return 村民信息
     */
    @Override
    public ClientUser selectClientUserById(Long id)
    {
        return clientUserMapper.selectClientUserById(id);
    }

    @Override
    public ClientUser selectByMasterNameAndIdCard(String masterName, String masterIdentityCardNumber) {
        return clientUserMapper.selectByMasterNameAndIdCard(masterName,masterIdentityCardNumber);
    }

    /**
     * 查询村民信息列表
     * 
     * @param clientUser 村民信息
     * @return 村民信息
     */
    @Override
    public List<ClientUser> selectClientUserList(ClientUser clientUser)
    {
        return clientUserMapper.selectClientUserList(clientUser);
    }

    @Override
    public List<ClientUser> selectClientUserByInput(String input,Long villageId) {

        List<ClientUser> clientUsers = clientUserMapper.selectClientUserByInput(input, villageId);
        clientUsers.forEach(i -> {
            i.setTotalAmount(clientUserOrderMapper.countClientUserTotal(i.getId()));
        });
        return clientUsers;
    }

    @Override
    public List<ClientUser> selectClientUserOrderList(Long villageId) {
        return clientUserMapper.selectClientUserOrderList(villageId);
    }

    /**
     * 新增村民信息
     * 
     * @param clientUser 村民信息
     * @return 结果
     */
    @Override
    public int insertClientUser(ClientUser clientUser)
    {
        clientUser.setCreateTime(DateUtils.getNowDate());
        return clientUserMapper.insertClientUser(clientUser);
    }

    /**
     * 修改村民信息
     * 
     * @param clientUser 村民信息
     * @return 结果
     */
    @Override
    public int updateClientUser(ClientUser clientUser)
    {
        clientUser.setUpdateTime(DateUtils.getNowDate());
        return clientUserMapper.updateClientUser(clientUser);
    }

    /**
     * 删除村民信息对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteClientUserByIds(String ids)
    {
        return clientUserMapper.deleteClientUserByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除村民信息信息
     * 
     * @param id 村民信息ID
     * @return 结果
     */
    @Override
    public int deleteClientUserById(Long id)
    {
        return clientUserMapper.deleteClientUserById(id);
    }

    /**
     * 批量添加居民信息
     * @param records
     */
    @Override
    public void batchInsertClientUsers(List<ClientUser> records) {
        clientUserMapper.batchInsertClientUsers(records);
    }

    @Override
    public int getAlarmCount(long villageId) {
        return clientUserMapper.countVillageAlarm(villageId);
    }

    @Override
    public int getNoteCount(long villageId) {
        return clientUserMapper.countVillageNote(villageId);
    }

    @Override
    public List<ClientUser> selectNoNoteList(long villageId) {
        List<ClientUser> clientUsers = clientUserMapper.selectClientUserByNote(villageId);
        clientUsers.forEach(i -> {
            i.setTotalAmount(clientUserOrderMapper.countClientUserTotal(i.getId()));
        });
        return clientUsers;
    }

    @Override
    public List<ClientUser> selectUnistallAlarmList(long villageId) {
        List<ClientUser> clientUsers = clientUserMapper.selectClientUserByAlarm(villageId);
        clientUsers.forEach(i -> {
            i.setTotalAmount(clientUserOrderMapper.countClientUserTotal(i.getId()));
        });
        return clientUsers;
    }

    @Override
    public List<ClientUser> selectXiangUnistallAlarmList(Long deptId) {
        List<ClientUser> clientUsers = clientUserMapper.selectXiangUnistallAlarmList(deptId);
        clientUsers.forEach(i -> {
            i.setTotalAmount(clientUserOrderMapper.countClientUserTotal(i.getId()));
        });
        return clientUsers;
    }

    @Override
    public List<ClientUser> selectXiangNoNoteList(Long deptId) {
        List<ClientUser> clientUsers = clientUserMapper.selectXiangNoNoteList(deptId);
        clientUsers.forEach(i -> {
            i.setTotalAmount(clientUserOrderMapper.countClientUserTotal(i.getId()));
        });
        return clientUsers;
    }

    @Override
    public int selectXiangUninstallAlarmCount(Long deptId) {
        return clientUserMapper.selectXiangUninstallAlarmCount(deptId);
    }

    @Override
    public int selectXiangNoNoteCount(Long deptId) {
        return clientUserMapper.selectXiangNoNoteCount(deptId);
    }

    @Override
    public TownStatistics selectXiangStatisitcsByXiangId(Long xiangId) {

        return clientUserMapper.selectXiangStatisitcsByXiangId(xiangId);
    }

    @Override
    public Long countBaolianHouseNum(Long baolianrenId) {
        return clientUserMapper.countBaolianHouseNum(baolianrenId);
    }

    @Override
    public Long sumBaolianPersonNum(Long baolianrenId) {
        return clientUserMapper.sumBaolianPersonNum(baolianrenId);
    }

    @Override
    public Long countVillagePopulation(Long villageId) {
        return clientUserMapper.countVillagePopulation(villageId);
    }

    @Override
    public Long countBaolianHouseNumByTown(Long townId) {
        return clientUserMapper.countBaolianHouseNumByTown(townId);
    }

    @Override
    public Long sumBaolianPersonNumByTown(Long townId) {
        return clientUserMapper.sumBaolianPersonNumByTown(townId);
    }

}
